#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve()
{
    int N;
    string S;
    cin >> N >> S;
    int i = 0;
    int cnt = 0;
    for (i = 0; i < N; i++)
    {
        if (S[i] == '1')
            cnt++;
    }
    for (i = 0; i < N; i++)
    {
        if (S[i] == '1')
            break;
    }
    if (cnt % 2 == 1)
        cout << -1 << endl;
    else if (cnt == 0)
        cout << 0 << endl;
    else if (S == "110" || S == "011")
        cout << -1 << endl;
    else if (S == "0110")
        cout << 3 << endl;
    else if (cnt == 2 && S[i + 1] == '1')
        cout << 2 << endl;
    else
        cout << cnt / 2 << endl;
}
int main()
{
    int t = 0;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
